package com.coocaa.ops.api.common.util;

import com.coocaa.ops.api.common.constant.ResponseCode;
import com.coocaa.ops.api.common.model.ResponseData;
import com.coocaa.ops.api.common.constant.ResponseMsg;


/**
 * @author tangminghong
 * @date 2020-02-10 17:51
 */
public class ResponseUtil {



    public ResponseUtil() {
    }

    public static <T> ResponseData<T> render(int code, String msg, T data) {
        ResponseData<T> resData = new ResponseData<>();
        resData.setCode(code);
        resData.setMsg(msg);
        resData.setData(data);
        return resData;
    }

    public static <T> ResponseData<T> renderSuccess(String msg, T data) {
        ResponseData<T> resData = new ResponseData<>();
        resData.setCode(ResponseCode.SUCCESS);
        resData.setMsg(msg);
        resData.setData(data);
        return resData;
    }

    public static <T> ResponseData<T> renderSuccess(T data) {
        ResponseData<T> resData = new ResponseData<>();
        resData.setCode(ResponseCode.SUCCESS);
        resData.setMsg(ResponseMsg.SUCCESS);
        resData.setData(data);
        return resData;
    }


    public static ResponseData renderFail(int code, String msg) {
        ResponseData<Object> resData = new ResponseData<>();
        resData.setCode(code);
        resData.setMsg(msg);
        resData.setData(null);
        return resData;
    }

}
